home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / cmds.fmt / ed.man < prev    next >
Encoding:
Text File  |  1989-02-07  |  20.8 KB  |  595 lines

  1.  
  2.  
  3.  
  4. ED                        User Commands                        ED
  5.  
  6.  
  7.  
  8. NNAAMMEE
  9.      ed - text editor
  10.  
  11. SSYYNNOOPPSSIISS
  12.      eedd [ -- ] [ --xx ] [ name ]
  13.  
  14. DDEESSCCRRIIPPTTIIOONN
  15.      _E_d is the standard text editor.
  16.  
  17.      If a _n_a_m_e argument is given, _e_d simulates an _e command (see
  18.      below) on the named file; that is to say, the file is read
  19.      into _e_d'_s buffer so that it can be edited.  If --xx is
  20.      present, an _x command is simulated first to handle an
  21.      encrypted file.  The optional -- suppresses the printing of
  22.      explanatory output and should be used when the standard
  23.      input is an editor script.
  24.  
  25.      _E_d operates on a copy of any file it is editing; changes
  26.      made in the copy have no effect on the file until a _w
  27.      (write) command is given.  The copy of the text being edited
  28.      resides in a temporary file called the _b_u_f_f_e_r.
  29.  
  30.      Commands to _e_d have a simple and regular structure: zero or
  31.      more _a_d_d_r_e_s_s_e_s followed by a single character _c_o_m_m_a_n_d, pos-
  32.      sibly followed by parameters to the command.  These
  33.      addresses specify one or more lines in the buffer.  Missing
  34.      addresses are supplied by default.
  35.  
  36.      In general, only one command may appear on a line.  Certain
  37.      commands allow the addition of text to the buffer.  While _e_d
  38.      is accepting text, it is said to be in _i_n_p_u_t _m_o_d_e. In this
  39.      mode, no commands are recognized; all input is merely col-
  40.      lected.  Input mode is left by typing a period `..' alone at
  41.      the beginning of a line.
  42.  
  43.      _E_d supports a limited form of _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n notation.
  44.      A regular expression specifies a set of strings of charac-
  45.      ters.  A member of this set of strings is said to be _m_a_t_c_h_e_d
  46.      by the regular expression.  In the following specification
  47.      for regular expressions the word `character' means any char-
  48.      acter but newline.
  49.  
  50.      1.   Any character except a special character matches
  51.           itself.  Special characters are the regular expression
  52.           delimiter plus \[..  and sometimes ^*$.
  53.  
  54.      2.   A .. matches any character.
  55.  
  56.      3.   A \ followed by any character except a digit or ()
  57.           matches that character.
  58.  
  59.      4.   A nonempty string _s bracketed [_s] (or [^_s]) matches any
  60.  
  61.  
  62.  
  63. Sprite v1.0              April 29, 1985                         1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ED                        User Commands                        ED
  71.  
  72.  
  73.  
  74.           character in (or not in) _s. In _s, \ has no special
  75.           meaning, and ] may only appear as the first letter.  A
  76.           substring _a-_b, with _a and _b in ascending ASCII order,
  77.           stands for the inclusive range of ASCII characters.
  78.  
  79.      5.   A regular expression of form 1-4 followed by * matches
  80.           a sequence of 0 or more matches of the regular expres-
  81.           sion.
  82.  
  83.      6.   A regular expression, _x, of form 1-8, bracketed \(_x\)
  84.           matches what _x matches.
  85.  
  86.      7.   A \ followed by a digit _n matches a copy of the string
  87.           that the bracketed regular expression beginning with
  88.           the _nth \( matched.
  89.  
  90.      8.   A regular expression of form 1-8, _x, followed by a reg-
  91.           ular expression of form 1-7, _y matches a match for _x
  92.           followed by a match for _y, with the _x match being as
  93.           long as possible while still permitting a _y match.
  94.  
  95.      9.   A regular expression of form 1-8 preceded by ^ (or fol-
  96.           lowed by $), is constrained to matches that begin at
  97.           the left (or end at the right) end of a line.
  98.  
  99.      10.  A regular expression of form 1-9 picks out the longest
  100.           among the leftmost matches in a line.
  101.  
  102.      11.  An empty regular expression stands for a copy of the
  103.           last regular expression encountered.
  104.  
  105.      Regular expressions are used in addresses to specify lines
  106.      and in one command (see _s below) to specify a portion of a
  107.      line which is to be replaced.  If it is desired to use one
  108.      of the regular expression metacharacters as an ordinary
  109.      character, that character may be preceded by `\'.  This also
  110.      applies to the character bounding the regular expression
  111.      (often `/') and to `\' itself.
  112.  
  113.      To understand addressing in _e_d it is necessary to know that
  114.      at any time there is a _c_u_r_r_e_n_t _l_i_n_e. Generally speaking, the
  115.      current line is the last line affected by a command; how-
  116.      ever, the exact effect on the current line is discussed
  117.      under the description of the command.  Addresses are con-
  118.      structed as follows.
  119.  
  120.      1.   The character `..' addresses the current line.
  121.  
  122.      2.   The character `$' addresses the last line of the
  123.           buffer.
  124.  
  125.      3.   A decimal number _n addresses the _n-th line of the
  126.  
  127.  
  128.  
  129. Sprite v1.0              April 29, 1985                         2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ED                        User Commands                        ED
  137.  
  138.  
  139.  
  140.           buffer.
  141.  
  142.      4.   `'_x' addresses the line marked with the name _x, which
  143.           must be a lower-case letter.  Lines are marked with the
  144.           _k command described below.
  145.  
  146.      5.   A regular expression enclosed in slashes `/' addresses
  147.           the line found by searching forward from the current
  148.           line and stopping at the first line containing a string
  149.           that matches the regular expression.  If necessary the
  150.           search wraps around to the beginning of the buffer.
  151.  
  152.      6.   A regular expression enclosed in queries `?' addresses
  153.           the line found by searching backward from the current
  154.           line and stopping at the first line containing a string
  155.           that matches the regular expression.  If necessary the
  156.           search wraps around to the end of the buffer.
  157.  
  158.      7.   An address followed by a plus sign `+' or a minus sign
  159.           `-' followed by a decimal number specifies that address
  160.           plus (resp. minus) the indicated number of lines.  The
  161.           plus sign may be omitted.
  162.  
  163.      8.   If an address begins with `+' or `-' the addition or
  164.           subtraction is taken with respect to the current line;
  165.           e.g. `-5' is understood to mean `..-5'.
  166.  
  167.      9.   If an address ends with `+' or `-', then 1 is added
  168.           (resp. subtracted).  As a consequence of this rule and
  169.           rule 8, the address `-' refers to the line before the
  170.           current line.  Moreover, trailing `+' and `-' charac-
  171.           ters have cumulative effect, so `--' refers to the
  172.           current line less 2.
  173.  
  174.      10.  To maintain compatibility with earlier versions of the
  175.           editor, the character `^' in addresses is equivalent to
  176.           `-'.
  177.  
  178.      Commands may require zero, one, or two addresses.  Commands
  179.      which require no addresses regard the presence of an address
  180.      as an error.  Commands which accept one or two addresses
  181.      assume default addresses when insufficient are given.  If
  182.      more addresses are given than such a command requires, the
  183.      last one or two (depending on what is accepted) are used.
  184.  
  185.      Addresses are separated from each other typically by a comma
  186.      `,,'.  They may also be separated by a semicolon `;;'.  In
  187.      this case the current line `..' is set to the previous
  188.      address before the next address is interpreted.  This
  189.      feature can be used to determine the starting line for for-
  190.      ward and backward searches (`/', `?').  The second address
  191.      of any two-address sequence must correspond to a line
  192.  
  193.  
  194.  
  195. Sprite v1.0              April 29, 1985                         3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ED                        User Commands                        ED
  203.  
  204.  
  205.  
  206.      following the line corresponding to the first address.  The
  207.      special form `%' is an abbreviation for the address pair
  208.      `1,$'.
  209.  
  210.      In the following list of _e_d commands, the default addresses
  211.      are shown in parentheses.  The parentheses are not part of
  212.      the address, but are used to show that the given addresses
  213.      are the default.
  214.  
  215.      As mentioned, it is generally illegal for more than one com-
  216.      mand to appear on a line.  However, most commands may be
  217.      suffixed by `p' or by `l', in which case the current line is
  218.      either printed or listed respectively in the way discussed
  219.      below.  Commands may also be suffixed by `n', meaning the
  220.      output of the command is to be line numbered.  These suf-
  221.      fixes may be combined in any order.
  222.  
  223.      (..)a
  224.      <text>
  225.      ..
  226.           The append command reads the given text and appends it
  227.           after the addressed line.  `..' is left on the last line
  228.           input, if there were any, otherwise at the addressed
  229.           line.  Address `0' is legal for this command; text is
  230.           placed at the beginning of the buffer.
  231.  
  232.      (.., ..)c
  233.      <text>
  234.      ..
  235.           The change command deletes the addressed lines, then
  236.           accepts input text which replaces these lines.  `..' is
  237.           left at the last line input; if there were none, it is
  238.           left at the line preceding the deleted lines.
  239.  
  240.      (.., ..)d
  241.           The delete command deletes the addressed lines from the
  242.           buffer.  The line originally after the last line
  243.           deleted becomes the current line; if the lines deleted
  244.           were originally at the end, the new last line becomes
  245.           the current line.
  246.  
  247.      e filename
  248.           The edit command causes the entire contents of the
  249.           buffer to be deleted, and then the named file to be
  250.           read in.  `..' is set to the last line of the buffer.
  251.           The number of characters read is typed.  `filename' is
  252.           remembered for possible use as a default file name in a
  253.           subsequent _r or _w command.  If `filename' is missing,
  254.           the remembered name is used.
  255.  
  256.      E filename
  257.           This command is the same as _e, except that no
  258.  
  259.  
  260.  
  261. Sprite v1.0              April 29, 1985                         4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. ED                        User Commands                        ED
  269.  
  270.  
  271.  
  272.           diagnostic results when no _w has been given since the
  273.           last buffer alteration.
  274.  
  275.      f filename
  276.           The filename command prints the currently remembered
  277.           file name.  If `filename' is given, the currently
  278.           remembered file name is changed to `filename'.
  279.  
  280.      (1,$)g/regular expression/command list
  281.           In the global command, the first step is to mark every
  282.           line which matches the given regular expression.  Then
  283.           for every such line, the given command list is executed
  284.           with `..' initially set to that line.  A single command
  285.           or the first of multiple commands appears on the same
  286.           line with the global command.  All lines of a multi-
  287.           line list except the last line must be ended with `\'.
  288.           _A, _i, and _c commands and associated input are permit-
  289.           ted; the `..' terminating input mode may be omitted if
  290.           it would be on the last line of the command list.  The
  291.           commands _g and _v are not permitted in the command list.
  292.  
  293.      (..)i
  294.  
  295.      <text>
  296.      ..
  297.           This command inserts the given text before the
  298.           addressed line.  `..' is left at the last line input,
  299.           or, if there were none, at the line before the
  300.           addressed line.  This command differs from the _a com-
  301.           mand only in the placement of the text.
  302.  
  303.      (.., ..+1)j
  304.           This command joins the addressed lines into a single
  305.           line; intermediate newlines simply disappear.  `..' is
  306.           left at the resulting line.
  307.  
  308.      ( .. )k_x
  309.           The mark command marks the addressed line with name _x,
  310.           which must be a lower-case letter.  The address form
  311.           `'_x' then addresses this line.
  312.  
  313.      (.., ..)l
  314.           The list command prints the addressed lines in an unam-
  315.           biguous way: non-graphic characters are printed in
  316.           two-digit octal, and long lines are folded.  The _l com-
  317.           mand may be placed on the same line after any non-i/o
  318.           command.
  319.  
  320.      (.., ..)m_a
  321.           The move command repositions the addressed lines after
  322.           the line addressed by _a.  The last of the moved lines
  323.           becomes the current line.
  324.  
  325.  
  326.  
  327. Sprite v1.0              April 29, 1985                         5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. ED                        User Commands                        ED
  335.  
  336.  
  337.  
  338.      (.., ..)p
  339.           The print command prints the addressed lines.  `..' is
  340.           left at the last line printed.  The _p command may be
  341.           placed on the same line after any non-i/o command.
  342.  
  343.      (.., ..)P
  344.           This command is a synonym for _p.
  345.  
  346.      q    The quit command causes _e_d to exit.  No automatic write
  347.           of a file is done.
  348.  
  349.      Q    This command is the same as _q, except that no diagnos-
  350.           tic results when no _w has been given since the last
  351.           buffer alteration.
  352.  
  353.      ($)r filename
  354.           The read command reads in the given file after the
  355.           addressed line.  If no file name is given, the remem-
  356.           bered file name, if any, is used (see _e and _f com-
  357.           mands).  The file name is remembered if there was no
  358.           remembered file name already.  Address `0' is legal for
  359.           _r and causes the file to be read at the beginning of
  360.           the buffer.  If the read is successful, the number of
  361.           characters read is typed.  `..' is left at the last line
  362.           read in from the file.
  363.  
  364.      ( .., ..)s/regular expression/replacement/       or,
  365.      ( .., ..)s/regular expression/replacement/g
  366.           The substitute command searches each addressed line for
  367.           an occurrence of the specified regular expression.  On
  368.           each line in which a match is found, all matched
  369.           strings are replaced by the replacement specified, if
  370.           the global replacement indicator `g' appears after the
  371.           command.  If the global indicator does not appear, only
  372.           the first occurrence of the matched string is replaced.
  373.           It is an error for the substitution to fail on all
  374.           addressed lines.  Any punctuation character may be used
  375.           instead of `/' to delimit the regular expression and
  376.           the replacement.  `..' is left at the last line substi-
  377.           tuted.
  378.  
  379.           An ampersand `&' appearing in the replacement is
  380.           replaced by the string matching the regular expression.
  381.           The special meaning of `&' in this context may be
  382.           suppressed by preceding it by `\'.  The characters `_\_n'
  383.           where _n is a digit, are replaced by the text matched by
  384.           the _n-th regular subexpression enclosed between `\('
  385.           and `\)'.  When nested, parenthesized subexpressions
  386.           are present, _n is determined by counting occurrences of
  387.           `\(' starting from the left.
  388.  
  389.           Lines may be split by substituting new-line characters
  390.  
  391.  
  392.  
  393. Sprite v1.0              April 29, 1985                         6
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. ED                        User Commands                        ED
  401.  
  402.  
  403.  
  404.           into them.  The new-line in the replacement string must
  405.           be escaped by preceding it by `\'.
  406.  
  407.           One or two trailing delimiters may be omitted, implying
  408.           the `p' suffix.  The special form `s' followed by _n_o
  409.           delimiters repeats the most recent substitute command
  410.           on the addressed lines.  The `s' may be followed by the
  411.           letters rr (use the most recent regular expression for
  412.           the left hand side, instead of the most recent left
  413.           hand side of a substitute command), pp (complement the
  414.           setting of the _p suffix from the previous substitu-
  415.           tion), or gg (complement the setting of the _g suffix).
  416.           These letters may be combined in any order.
  417.  
  418.      (.., ..)t_a
  419.           This command acts just like the _m command, except that
  420.           a copy of the addressed lines is placed after address _a
  421.           (which may be 0).  `..' is left on the last line of the
  422.           copy.
  423.  
  424.      (.., ..)u
  425.           The undo command restores the buffer to it's state
  426.           before the most recent buffer modifying command.  The
  427.           current line is also restored.  Buffer modifying com-
  428.           mands are _a, _c, _d, _g, _i, _k, and _v. For purposes of
  429.           undo, _g and _v are considered to be a single buffer
  430.           modifying command.  Undo is its own inverse.
  431.  
  432.           When _e_d runs out of memory (at about 8000 lines on any
  433.           16 bit mini-computer such as the PDP-11) This full undo
  434.           is not possible, and _u can only undo the effect of the
  435.           most recent substitute on the current line.  This res-
  436.           tricted undo also applies to editor scripts when _e_d is
  437.           invoked with the -- option.
  438.  
  439.      (1, $)v/regular expression/command list
  440.           This command is the same as the global command _g except
  441.           that the command list is executed _g with `..' initially
  442.           set to every line _e_x_c_e_p_t those matching the regular
  443.           expression.
  444.  
  445.      (1, $)w filename
  446.           The write command writes the addressed lines onto the
  447.           given file.  If the file does not exist, it is created.
  448.           The file name is remembered if there was no remembered
  449.           file name already.  If no file name is given, the
  450.           remembered file name, if any, is used (see _e and _f com-
  451.           mands).  `..' is unchanged.  If the command is success-
  452.           ful, the number of characters written is printed.
  453.  
  454.      (1, $)W filename
  455.           This command is the same as _w, except that the
  456.  
  457.  
  458.  
  459. Sprite v1.0              April 29, 1985                         7
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. ED                        User Commands                        ED
  467.  
  468.  
  469.  
  470.           addressed lines are appended to the file.
  471.  
  472.      (1, $)wq filename
  473.           This command is the same as _w except that afterwards a
  474.           _q command is done, exiting the editor after the file is
  475.           written.
  476.  
  477.      x    A key string is demanded from the standard input.
  478.           Later _r, _e and _w commands will encrypt and decrypt the
  479.           text with this key by the algorithm of _c_r_y_p_t(1).  An
  480.           explicitly empty key turns off encryption.
  481.           (..+1)z    or,
  482.      (..+1)z_n
  483.           This command scrolls through the buffer starting at the
  484.           addressed line.  22 (or _n, if given) lines are printed.
  485.           The last line printed becomes the current line.  The
  486.           value _n is sticky, in that it becomes the default for
  487.           future _z commands.
  488.  
  489.      ($)= The line number of the addressed line is typed.  `..' is
  490.           unchanged by this command.
  491.  
  492.      !<shell command>
  493.           The remainder of the line after the `!' is sent to
  494.           _s_h(1) to be interpreted as a command.  `..' is
  495.           unchanged.
  496.  
  497.      (..+1,..+1)<newline>
  498.           An address alone on a line causes the addressed line to
  499.           be printed.  A blank line alone is equivalent to
  500.           `.+1p'; it is useful for stepping through text.  If two
  501.           addresses are present with no intervening semicolon, _e_d
  502.           prints the range of lines.  If they are separated by a
  503.           semicolon, the second line is printed.
  504.  
  505.      If an interrupt signal (ASCII DEL) is sent, _e_d prints
  506.      `?interrupted' and returns to its command level.
  507.  
  508.      Some size limitations: 512 characters per line, 256 charac-
  509.      ters per global command list, 64 characters per file name,
  510.      and, on mini computers, 128K characters in the temporary
  511.      file.  The limit on the number of lines depends on the
  512.      amount of core: each line takes 2 words.
  513.  
  514.      When reading a file, _e_d discards ASCII NUL characters and
  515.      all characters after the last newline.  It refuses to read
  516.      files containing non-ASCII characters.
  517.  
  518. FFIILLEESS
  519.      /tmp/e*
  520.      edhup: work is saved here if terminal hangs up
  521.  
  522.  
  523.  
  524.  
  525. Sprite v1.0              April 29, 1985                         8
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. ED                        User Commands                        ED
  533.  
  534.  
  535.  
  536. SSEEEE AALLSSOO
  537.      B. W. Kernighan, _A _T_u_t_o_r_i_a_l _I_n_t_r_o_d_u_c_t_i_o_n _t_o _t_h_e _E_D _T_e_x_t _E_d_i_-
  538.      _t_o_r
  539.      B. W. Kernighan, _A_d_v_a_n_c_e_d _e_d_i_t_i_n_g _o_n _U_N_I_X
  540.      ex(1), sed(1), crypt(1)
  541.  
  542. DDIIAAGGNNOOSSTTIICCSS
  543.      `?name' for inaccessible file; `?self-explanatory message'
  544.      for other errors.
  545.  
  546.      To protect against throwing away valuable work, a _q or _e
  547.      command is considered to be in error, unless a _w has
  548.      occurred since the last buffer change.  A second _q or _e will
  549.      be obeyed regardless.
  550.  
  551. BBUUGGSS
  552.      The _l command mishandles DEL.
  553.      The _u_n_d_o command causes marks to be lost on affected lines.
  554.      The _x command, --xx option, and special treatment of hangups
  555.      only work on UNIX.
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591. Sprite v1.0              April 29, 1985                         9
  592.  
  593.  
  594.  
  595.